package com.neusoft.springboot07.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neusoft.springboot07.dao.mapper.TItemMapper;
import com.neusoft.springboot07.domain.TItem;
import com.neusoft.springboot07.domain.TItemExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ItemsService {

    @Autowired
    private TItemMapper tItemMapper;

    public PageInfo<TItem> queryUserByPage(int pageNo, int PageSize) {
        Page<TItem> page = PageHelper.startPage((pageNo-1)*PageSize, PageSize,"id,price ASC");

        TItemExample tItemExample = new TItemExample();
        tItemExample.setDistinct(true);
        tItemExample.createCriteria()
                .andPnameLike("辣%")
                .andPriceBetween(1l,50l);
        // and pname like '' and price 1 50
        List<TItem> list = tItemMapper.selectByExample(tItemExample);
        return page.toPageInfo();
    }
}
